<?php

namespace app\common\model;

use think\Model;

class Iotgoods extends Model
{
    // 表名
    protected $name = 'iotgoods';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'cate_text',
        'rebate_rule_text',
        'sale_text'
    ];
	
	const FIXED = 1;
	const OPTIONAL = 2;
	const FLOW = 3;
	const DEVICE_PKG = 4;
	
	public static $_cate = [
		'fixed'=>self::FIXED,
		'optional'=>self::OPTIONAL,
		'flow'=>self::FLOW,
		'device'=>self::DEVICE_PKG,
	];
    
    public function getCateList()
    {
        return ['1' => __('物联卡基础套餐'), '2' => __('物联卡自选包'), '3' => __('物联卡加餐包'), '4' => __('设备套餐')];
    }     

    public function getRebateRuleList()
    {
        //1为全局规则,2为商品规则
        return ['1' => __('全局规则'), '2' => __('为商品规则')];
    }     


    public function getSaleList()
    {
        //1为全局规则,2为商品规则
        return ['n' => __('否'), '2' => __('是')];
    }


    public function getCateTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['cate'];
        $list = $this->getCateList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getRebateRuleTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['rebate_rule'];
        $list = $this->getRebateRuleList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getSaleTextAttr($value, $data)
    {
        $value = $value ? $value : $data['sale'];
        $list = $this->getSaleList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
